Skip to content

gh-157710: Soft deprecate C API modifying str objects - #157711

Open
vstinner wants to merge 8 commits into
python:mainfrom
vstinner:deprecate_unicode_capi
Open

vstinner wants to merge 8 commits into
python:mainfrom
vstinner:deprecate_unicode_capi

Conversation

@vstinner

@vstinner vstinner commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Soft deprecate PyUnicode_New(), PyUnicode_CopyCharacters(), PyUnicode_Fill(), PyUnicode_Resize(), PyUnicode_WRITE() and PyUnicode_WriteChar() functions. Use the PyUnicodeWriter API instead.

Soft deprecate PyUnicode_New(), PyUnicode_CopyCharacters(),
PyUnicode_Fill(), PyUnicode_Resize(), PyUnicode_WRITE() and
PyUnicode_WriteChar() functions. Use the PyUnicodeWriter API instead.

Mention also that PyUnicodeWriter is not thread safe.
@vstinner

Copy link
Copy Markdown
Member Author

@read-the-docs-community

read-the-docs-community Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34934164 | 📁 Comparing 9d03d07 against main (5539c2a)

  🔍 Preview build  

51 files changed · + 1 added · ± 50 modified

+ Added

± Modified

@encukou

encukou commented Sep 18, 2026

Copy link
Copy Markdown
Member

It looks like this should be a WG decision. I'd vote for it though.

@vstinner

Copy link
Copy Markdown
Member Author

@encukou:

It looks like this should be a WG decision. I'd vote for it though.

Ok. I created capi-workgroup/decisions#111 to get a decision from the C API Working Group. I added more details: list of PyPI affected project and mention that pythoncapi-compat provides the PyUnicodeWriter API on Python 3.6-3.13.

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 2, 2026
test_capi.test_unicode:

* Add tests on PyUnicode_New() and PyUnicode_Resize(). Check that the
  result is either a mutable string, or the empty string singleton.
* Check that PyUnicode_Fill(), PyUnicode_CopyCharacters() and
  PyUnicode_WriteChar() fail to modify a string with 2 references.

Adjust documentation.
@vstinner
vstinner enabled auto-merge (squash) October 2, 2026 20:33
@vstinner

vstinner commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

The C API Working Group approved the soft deprecation: capi-workgroup/decisions#111 (comment).

@StanFromIreland

Copy link
Copy Markdown
Member

@vstinner auto-merge is failing because this requires a PR review (since it's labelled type-feature), and there are conflicts. I'll disable it for now.

@vstinner

vstinner commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

@vstinner auto-merge is failing because this requires a PR review (since it's labelled type-feature), and there are conflicts. I'll disable it for now.

Ah right, there was a conflict. It's now solved.

@picnixz added "type-feature" on the issue, and the PR inherited the label. It means that another core dev should review the change?

@picnixz

picnixz commented Oct 4, 2026

Copy link
Copy Markdown
Member

Ah crap. I still think it's a feature but I don't think it needs a core dev approval... I don't like this new label stuff because this means we just can't make triaging better (I do appreciate when we know whether a change will be backported or not just by seeing the feature type).

@picnixz picnixz removed the type-feature A feature request or enhancement label Oct 4, 2026
@picnixz

picnixz commented Oct 4, 2026

Copy link
Copy Markdown
Member

Would this work like that..?

@picnixz

picnixz commented Oct 4, 2026

Copy link
Copy Markdown
Member

Ok, I think we need to come up with a better reading of when something needs a type-feature really. It totally breaks my triaging.

@StanFromIreland

Copy link
Copy Markdown
Member

Would this work like that..?

The bot will just re-add it I'm afraid, although it works to merge if you do it shortly after and don't touch the PR.

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the easiest solution is to just approve the PR :)

I left a few grammar nitpicks below. The rest of this looks good to me.

Comment thread Doc/c-api/unicode.rst Outdated
Comment thread Doc/c-api/unicode.rst Outdated
Comment thread Doc/c-api/unicode.rst Outdated
Comment thread Doc/c-api/unicode.rst Outdated
Comment thread Doc/c-api/unicode.rst Outdated
Comment thread Doc/c-api/unicode.rst Outdated
Comment thread Doc/c-api/unicode.rst Outdated
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 4, 2026
@vstinner
vstinner enabled auto-merge (squash) October 4, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge docs Documentation in the Doc dir type-feature A feature request or enhancement

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

5 participants